import request from '@/utils/request'

// 获取用户列表
export function userList(searchDto) {
    return request({
        url: '/sysUser/getUserList',
        method: 'post',
        data: searchDto
    })
}

//添加用户
export function saveUser(data) {
    return request({
        url: '/sysUser/saveUser',
        method: 'post',
        data
    })
}

//添加用户
export function deleteUser(ids) {
    return request({
        url: '/sysUser/deleteUser',
        method: 'delete',
        data: ids
    })
}

//导出模板
export function exportTemplate() {
    return request({
        url: '/sysUser/exportTemplate',
        method: 'post',
        responseType: 'blob',
        contentType:'application/vnd.ms-excel;charset=UTF-8'
    })
}

//导入用户
export function importUser(file) {
    return request({
        url: '/sysUser/importUser',
        method: 'post',
        data: file,
        headers : { 'Content-type':'multipart/form-data'}
    })
}

//导出用户
export function exportUser() {
    return request({
        url: '/sysUser/export',
        method: 'post',
        responseType: "blob"
    })
}

//得到修改用户信息
export function getEditUser(userId) {
    return request({
        url: '/sysUser/getEditUser/'+userId,
        method: 'get',
    })
}

//修改用户
export function editUser(data) {
    return request({
        url: '/sysUser/edit/',
        method: 'put',
        data
    })
}

//获取所有角色列表
export function getAllRoleList() {
    return request({
        url: '/sysUser/getAllRoleList/',
        method: 'get'
    })
}

//根据userId获取角色
export function getAllRolByUserId(userId) {
  return request({
    url: '/user/getRoleList/'+userId,
    method: 'get'
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/sysUser/avatar',
    method: 'post',
    data,
    headers : { 'Content-type':'multipart/form-data'}
  })
}

// 用户密码重置
export function updateUserPwd(newPassword) {
  const data = {
    newPassword
  }
  return request({
    url: '/sysUser/resetPwd',
    method: 'put',
    params: data
  })
}

// 获取用户基本信息
export function getProfile() {
  return request({
    url: '/sysUser/getProfile',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/sysUser/profile',
    method: 'put',
    data
  })
}

